<template>
  <div class="middleware_state">
    <div class="header_title">
      <span>系统自动分析异常卡</span>
    </div>
    <div class="list">
      <el-form ref="alldata" :model="alldata" :rules="alldatarule" :label-position="labelPosition">
        <el-form-item
          label="最近一次自动分析时间:"
          prop="whiteListIp"
        >{{alldata.lastUpdateTime}}</el-form-item>
        <el-form-item label="每日开始时间:">
          <el-time-picker
            style="width:110px"
            v-model="alldata.startTime"
            value-format="HH:mm:ss"
            placeholder="每日开始时间"
            :clearable="false"
            size="mini"
          ></el-time-picker>
        </el-form-item>
        <el-form-item label="每日结束时间:">
          <el-time-picker
            style="width:110px"
            v-model="alldata.endTime"
            value-format="HH:mm:ss"
            placeholder="每日结束时间"
            :clearable="false"
            size="mini"
          ></el-time-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateSubmit">更新配置</el-button>
        </el-form-item>
      </el-form>
      <h4>指定单位分析</h4>
      <el-form ref="form" :model="elform" :rules="elformrule" >
        <el-form-item label="学校编号:" prop="schoolCode">
          <el-col :span="4">
            <el-input v-model="elform.schoolCode" size="mini" placeholder="学校编号"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="analysisSubmit">立即分析</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      datetime: [],
      time: [],
    //   url: 'http://192.168.13.235:9000',
      url: 'https://shujuxiaoyuan.com:9000',
      labelPosition: 'right',
      alldata: {
        endTime: '00:00:00',
        lastUpdateTime: '',
        pkSettingId: 1,
        startTime: '23:59:59'
      },
      alldatarule: {},
      elform: {
        schoolCode: ''
      },
      elformrule: {
        schoolCode: [
          { required: true, message: '请填写学校编号', trigger: 'change' }
        ]
      }
    }
  },
  created() {
    this.changeschoolid = this.$store.state.user.changeschoolid
    this.administrator = sessionStorage.getItem('administrator')
  },
  mounted() {
    this.midsearch()
  },
  methods: {
    midsearch() {
      this.$http({
        // url: 'https://shujuxiaoyuan.com:9000/card-exception/analysis',
        url: this.url + '/card-exception/get-settings',
        method: 'post',
        data: this.$http.adornData({
          messageContent: this.administrator
          //   messageType: 0
        })
      }).then(({ data }) => {
        if (data.messageCode === 200) {
          this.alldata = { ...data.messageContent }
        } else {
          this.$message.error(data.errorMessage)
        }
      })
    },
    // 更新分析时间
    updateSubmit() {
      //   this.alldata.administrator = this.changeschoolid
      this.$refs['alldata'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.url + '/card-exception/update-settings',
            method: 'post',
            data: this.$http.adornData({
              messageContent: this.alldata
            })
          }).then(({ data }) => {
            if (data.messageCode === 200) {
              this.$message({
                showClose: true,
                message: '配置成功',
                type: 'success'
              })
              this.midsearch()
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    },
    // 分析
    analysisSubmit() {
      // this.alldata.unitGuid = this.changeschoolid
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.$http({
            url: this.url + '/card-exception/analysis',
            method: 'post',
            data: this.$http.adornData({
              messageContent: this.elform.schoolCode
            })
          }).then(({ data }) => {
            if (data.messageCode === 200) {
              this.$message({
                showClose: true,
                message: '分析完成',
                type: 'success'
              })
            } else {
              this.$message.error(data.errorMessage)
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.middleware_state {
  padding: 10px;
  .header_title {
    //  text-indent: 22px;
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid #e5e9f2;
    color: #909399;
  }
  .list {
    font-size: 16px;
    font-weight: bold;
    color: #909399;
    padding-top: 20px;
    .el-form-item {
      padding-left: 22px;
      margin-bottom: 14px;
      // padding-top: 18px;
      // border-bottom: 1px solid #e5e9f2;
      width: 100%;
    }
    .el-form-item:last-child {
      //   border-bottom: 0px solid #e5e9f2;
      //   margin-top: 30px;
    }
  }
}
</style>